/*
 * Copyright 2013-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.svn.demos.web;

import com.example.svn.demos.common.AjaxResult;
import com.example.svn.demos.service.BasicService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
 */
@RestController
@RequestMapping("/basic")
public class BasicController {
    @Autowired
    private BasicService basicService;

    @RequestMapping("/editPassword")
    public AjaxResult editPassword(String userName,String newPassword){
        System.out.println("访问修改密码接口"+"userName:"+userName+" newPassword:"+newPassword);
        if (userName==null||"".equals(userName)||newPassword==null||"".equals(newPassword)){
            return AjaxResult.error(500,"用户名或密码不能为空");
        }


        boolean edit= basicService.editPassword(userName,newPassword);
        if (!edit){
            return AjaxResult.error(500,"系统错误");
        }

        return AjaxResult.success("修改成功");
    }

    @RequestMapping("/test")
    public AjaxResult test(String userName,String newPassword){
        System.out.println("测试接口");
        HashMap<String, Object> map = new HashMap<>();
        map.put("userName",userName);
        map.put("newPassword",newPassword);

        return AjaxResult.success().put("map",map);
    }


}
